package web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import pojo.SysUser;
import utils.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SysInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否登录
        SysUser sysUser=(SysUser) request.getSession().getAttribute(Constants.USER_SESSION);
        if(sysUser==null){
            //引导用户来到登录页面
            response.sendRedirect(request.getContextPath()+"/toLogin");
            return false;
        }

        return true;
    }
}
